package com.zjkj.mp.dao.customer.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zjkj.mp.dao.DaoBase;
import com.zjkj.mp.dao.customer.GroupDao;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.customer.Group;

@Repository
public class GroupDaoImpl extends DaoBase implements GroupDao {

	@SuppressWarnings("unchecked")
	public List<Group> getGroupList(int groupId) {
		List<Group> list = getSqlMapClient().queryForList("get.groupList", groupId);
		return list;
	}

	public int insertGroup(Group group) {
		int num = getSqlMapClient().update("ins.insertGroup", group);
		return num;
	}

	public int delGroup(int groupId) {
		int num = getSqlMapClient().delete("del.delGroup", groupId);
		return num;
	}

	public int updGroup(Group group) {
		int num = getSqlMapClient().update("upd.updGroup", group);
		return num;
	}

	@SuppressWarnings("unchecked")
	public List<Group> getGroupList() {
		List<Group> list = getSqlMapClient().queryForList("get.groupAllList");
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public PaginatedResult getGroupPageList(int nowPage, int maxRow, Map<String, Object> map) {
		if(map == null) 
			map= new HashMap<String, Object>();
		
		PaginatedResult result = new PaginatedResult(nowPage, maxRow);
		List<Group> group =  this.getSqlMapClient().queryForList("get.groupPageList", map, (nowPage-1)*maxRow, maxRow);
		result.setResult(group);
 
		int count = ((Integer)this.getSqlMapClient().queryForObject("get.groupPageListCount",map)).intValue();
		result.setTotalSize(count);
		
		return result;
	}

}
